<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="120px">
      <el-form-item label="考试项目" prop="projectName"  :rules=" { required: true, message: '请选择', trigger: 'blur' }">
        <el-select v-model="queryParams.projectName" filterable placeholder="请选择" class="selectWidth">
          <el-option
            v-for="dict in projectIdList"
            :key="dict.name"
            :label="dict.name"
            :value="dict.name"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="大于次数" prop="count" :rules=" { required: true, message: '请输入', trigger: 'blur' }">
        <el-input
          v-model="queryParams.count"
          placeholder="请输入大于1的数"
          clearable
          size="small"
          type="number"
          min="1"
        />
      </el-form-item>
      <el-form-item label="开始时间" prop="startTime" :rules=" { required: true, message: '请选择', trigger: 'blur' }">
        <el-date-picker clearable size="small"
                        v-model="queryParams.startTime"
                        type="datetime"
                        value-format="yyyy-MM-dd HH:mm:ss"
                        placeholder="选择开始时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="结束时间" prop="endTime" :rules=" { required: true, message: '请选择', trigger: 'blur' }">
        <el-date-picker clearable size="small"
                        v-model="queryParams.endTime"
                        type="datetime"
                        value-format="yyyy-MM-dd HH:mm:ss"
                        placeholder="选择结束时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="exportList"
        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <el-table v-loading="loading" :data="examProject">
      <el-table-column label="准考号" align="center" prop="zkh"/>
      <el-table-column label="考生名称" align="center" prop="ksName"/>
      <el-table-column label="考试项目" align="center" prop="projectName"/>
      <el-table-column label="中学名称" align="center" prop="zxmc"/>
      <el-table-column label="考试次数" align="center" prop="count"/>
    </el-table>


  </div>
</template>
<script>
import {
  examProjectsList,
  examProjectCount,
  examProjectCountExport
} from '@/api/business/candidate/candidate'

export default {
  name: 'examProject',
  data() {
    return {
      data: [],
      filterMethod(query, item) {
        return item.users.indexOf(query) > -1
      },
      // 遮罩层
      loading: false,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 支持项目表格数据
      examProject: [],
      // 弹出层标题
      title: '',
      usertitle: '',
      // 是否显示弹出层
      open: false,
      useropen: false,
      // 查询参数
      queryParams: {
        count: 1
      },
      projectIdList: [],

    }
  },
  created() {
    examProjectsList().then(response => {
      this.projectIdList = response.data
    })
  },
  methods: {
    getList() {
      this.loading = true
      examProjectCount(this.queryParams).then(response => {
        this.examProject = response.data
        this.loading = false
      })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.$refs['queryForm'].validate(valid => {
        if (valid) {
          this.loading=true
          this.queryParams.pageNo = 1
          this.getList()
        }
      }
      )
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    /** 导出按钮操作 */
    exportList() {
      const queryParams = this.queryParams;
      this.$modal.confirm('是否确认导出所有数据项？').then(() => {
        this.exportLoading = true;
        return examProjectCountExport(queryParams);
      }).then(response => {
        this.$download.name(response.msg);
        this.exportLoading = false;
      }).catch(() => {});
    }
  }
}
</script>
